﻿/*
**签约报备页面
*/
Chenxin.UI.ContractArchivePage = Chenxin.extend(Chenxin.UI.AddPageCommon, {
    actionUrl: "/service/logic/ContractArchive.ashx",
    createForm: function() {

        this.jqmReview = new Chenxin.UI.Win({
            id: 'jqmReview',
            width: 700,
            height: 600,
            title: '签约报备预览',
            content: '',
            createBtn: function() {
                return [{ text: '取消', handler: this.hide}]
            }
        });

        return new Chenxin.UI.ContractArchiveForm({
            scope: this
        });
    },
    customerInit: function() {
    },
    getReviewInfo: function() {
        var strRet = "";
        var json = Chenxin.Fn.getFormJson(this.form.id, this.form.comboList);

        //报备信息
        strRet = strRet + "<table class='tabsorternew table_archive' style='width:100%'>";
        strRet = strRet + "<thead>";
        strRet = strRet + "<tr>";
        strRet = strRet + "<th colspan='8'>";
        strRet = strRet + "<span>报备信息</span>";
        strRet = strRet + "</th>";
        strRet = strRet + "</tr>";
        strRet = strRet + "</thead>";
        strRet = strRet + "<tbody>";

        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='width:80px;text-align:right;'>签约方式</th>";
        strRet = strRet + "<td style='width:150'>" + json.BargainType + "</td>";
        strRet = strRet + "<th style='width:80px;text-align:right;'>签约时间</th>";
        strRet = strRet + "<td style='width:150'>" + json.BargainTime + "</td>";
        strRet = strRet + "<th style='width:80px;text-align:right;'>签贷款时间</th>";
        strRet = strRet + "<td>" + json.LoanTime + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='width:80px;text-align:right;'>签约地点</th>";
        strRet = strRet + "<td style='width:150'>" + json.WorkDepartName + "</td>";
        strRet = strRet + "<th style='width:80px;text-align:right;'>签约人</th>";
        strRet = strRet + "<td style='width:150'>" + json.WorkPersonName + "</td>";
        strRet = strRet + "<th style='width:80px;text-align:right;'>合同归属</th>";
        strRet = strRet + "<td>" + json.BargainCompanyName + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='width:80px;text-align:right;'>贷款情况</th>";
        strRet = strRet + "<td style='width:150'>" + json.LoanInfo + "</td>";
        strRet = strRet + "<th style='width:80px;text-align:right;'>报备部门</th>";
        strRet = strRet + "<td style='width:150'>" + json.DepartName + "</td>";
        strRet = strRet + "<th style='width:80px;text-align:right;'>报备人员</th>";
        strRet = strRet + "<td>" + json.Employee + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='width:80px;text-align:right;'>联系电话</th>";
        strRet = strRet + "<td style='width:150'>" + json.Mobile + "</td>";
        strRet = strRet + "<th style='width:80px;text-align:right;'>特殊情况</th>";
        strRet = strRet + "<td colspan='3'>" + json.SpecialInfo + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "</tbody>";
        strRet = strRet + "</table>";

        //房源信息
        strRet = strRet + "<table class='tabsorternew table_archive' style='width:100%'>";
        strRet = strRet + "<thead>";
        strRet = strRet + "<tr>";
        strRet = strRet + "<th colspan='8'>";
        strRet = strRet + "<span>房源信息</span>";
        strRet = strRet + "</th>";
        strRet = strRet + "</tr>";
        strRet = strRet + "</thead>";
        strRet = strRet + "<tbody>";
        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='text-align:right;'>房源编号</th>";
        strRet = strRet + "<td colspan='3'>" + json.HouseCode + "</td>";
        strRet = strRet + "<th style='text-align:right;'>产权证号</th>";
        strRet = strRet + "<td colspan='3'>" + json.PropertyCode + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='text-align:right;'>房源地址</th>";
        strRet = strRet + "<td colspan='7'>" + json.NewHouseAddress + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='width:80px;text-align:right;'>建筑面积</th>";
        strRet = strRet + "<td style='width:95'>" + json.BuildingArea + "</td>";
        strRet = strRet + "<th style='width:80px;text-align:right;'>房屋楼层</th>";
        strRet = strRet + "<td style='width:95'>" + json.Cur_Floor + "</td>";
        strRet = strRet + "<th style='width:80px;text-align:right;'>总楼层</th>";
        strRet = strRet + "<td style='width:95'>" + json.Total_Floor + "</td>";
        strRet = strRet + "<th style='width:80px;text-align:right;'>竣工日期</th>";
        strRet = strRet + "<td>" + json.CompleteYear + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='text-align:right;'>建筑类型</th>";
        strRet = strRet + "<td>" + json.BuildingType + "</td>";
        strRet = strRet + "<th style='text-align:right;'>物业用途</th>";
        strRet = strRet + "<td>" + json.HouseUse + "</td>";
        strRet = strRet + "<th style='text-align:right;'>所属业务员</th>";
        strRet = strRet + "<td>" + json.BelongUserName + "</td>";
        strRet = strRet + "<th style='text-align:right;'>所属门店</th>";
        strRet = strRet + "<td>" + json.BelongUserDepartmentName + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "</tbody>";
        strRet = strRet + "</table>";

        //交易信息
        strRet = strRet + "<table class='tabsorternew table_archive' style='width:100%'>";
        strRet = strRet + "<thead>";
        strRet = strRet + "<tr>";
        strRet = strRet + "<th colspan='8'>";
        strRet = strRet + "<span>交易信息</span>";
        strRet = strRet + "</th>";
        strRet = strRet + "</tr>";
        strRet = strRet + "</thead>";
        strRet = strRet + "<tbody>";
        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='width:100px;text-align:right;'>合同总价</th>";
        strRet = strRet + "<td style='width:130px'>" + json.TotalPrice + json.Unit + "</td>";
        strRet = strRet + "<th style='width:100px;text-align:right;'>补偿款</th>";
        strRet = strRet + "<td style='width:130px'>" + json.FitPrice + "</td>";
        strRet = strRet + "<th style='width:100px;text-align:right;'>抵押情况</th>";
        strRet = strRet + "<td>" + json.MortgageInfo + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='text-align:right;'>还贷时间</th>";
        strRet = strRet + "<td>" + json.PayLoanDay + "</td>";
        strRet = strRet + "<th style='text-align:right;'>维修基金</th>";
        strRet = strRet + "<td>" + json.RepairFund + "</td>";
        strRet = strRet + "<th style='text-align:right;'>交房时间</th>";
        strRet = strRet + "<td>" + json.GiveHouseTime + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='text-align:right;'>公证情况</th>";
        strRet = strRet + "<td colspan='8'>" + json.FariInfo + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='text-align:right;'>付款方式</th>";
        strRet = strRet + "<td colspan='8'>" + json.PayMode + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='text-align:right;'>固定装修附送设<br />施设备家电家具</th>";
        strRet = strRet + "<td colspan='8'>" + json.Remark + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='text-align:right;'>租约</th>";
        strRet = strRet + "<td colspan='8'>" + json.FairPoint + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "</tbody>";
        strRet = strRet + "</table>";

        //出售(甲)方信息
        strRet = strRet + "<table class='tabsorternew table_archive' style='width:100%'>";
        strRet = strRet + "<thead>";
        strRet = strRet + "<tr>";
        strRet = strRet + "<th colspan='8'>";
        strRet = strRet + "<span>出售(甲)方信息</span>";
        strRet = strRet + "</th>";
        strRet = strRet + "</tr>";
        strRet = strRet + "</thead>";
        strRet = strRet + "<tbody>";
        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='text-align:right;width:80px'>联系地址</th>";
        strRet = strRet + "<td style='width:270px'>" + json.VenderAddress + "</td>";
        strRet = strRet + "<th style='text-align:right;width:80px'>联系电话</th>";
        strRet = strRet + "<td>" + json.VenderTel + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "<tr>";
        strRet = strRet + "<th colspan=2 style='text-align:center;'>姓名</th>";
        strRet = strRet + "<th colspan=2 style='text-align:center;'>身份证号</th>";
        strRet = strRet + "</tr>";

        var CustomerName;
        var IDNum;
        $("#tbVerder tr").each(function() {
            strRet = strRet + "<tr>";
            if ($(this).find("input[name='CustomerName']").length > 0) {
                CustomerName = $(this).find("input[name='CustomerName']").val();
                IDNum = $(this).find("input[name='IDNum']").val();

                if (CustomerName != "" || IDNum != "") {
                    strRet = strRet + "<td colspan='2' style='text-align:center'>" + CustomerName + "</td>";
                    strRet = strRet + "<td colspan='2' style='text-align:center'>" + IDNum + "</td>";
                }
            }
            strRet = strRet + "</tr>";
        });

        strRet = strRet + "</tbody>";
        strRet = strRet + "</table>";

        //买受(乙)方信息
        strRet = strRet + "<table class='tabsorternew table_archive' style='width:100%'>";
        strRet = strRet + "<thead>";
        strRet = strRet + "<tr>";
        strRet = strRet + "<th colspan='8'>";
        strRet = strRet + "<span>买受(乙)方信息</span>";
        strRet = strRet + "</th>";
        strRet = strRet + "</tr>";
        strRet = strRet + "</thead>";
        strRet = strRet + "<tbody>";
        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='text-align:right;width:80px;'>联系地址</th>";
        strRet = strRet + "<td colspan=2 style='width:270px'>" + json.BuyerAddress + "</td>";
        strRet = strRet + "<th style='text-align:right;width:80px;'>联系电话</th>";
        strRet = strRet + "<td colspan=2>" + json.BuyerTel + "</td>";
        strRet = strRet + "</tr>";

        strRet = strRet + "<tr>";
        strRet = strRet + "<th style='text-align:center;'>姓名</th>";
        strRet = strRet + "<th style='text-align:center;'>身份证号</th>";
        strRet = strRet + "<th style='text-align:center;'>公积金帐号</th>";
        strRet = strRet + "<th style='text-align:center;'>配偶姓名</th>";
        strRet = strRet + "<th style='text-align:center;'>身份证号</th>";
        strRet = strRet + "<th style='text-align:center;'>公积金帐号</th>";
        strRet = strRet + "</tr>";
        var GJJNum;
        var SpousesName;
        var SpousesIDNum;
        var SpousesGJJNum;
        $("#tbBuyer tr").each(function() {

            if ($(this).find("input[name='CustomerName']").length > 0) {
                CustomerName = $(this).find("input[name='CustomerName']").val();
                IDNum = $(this).find("input[name='IDNum']").val();
                GJJNum = $(this).find("input[name='GJJNum']").val();
                SpousesName = $(this).find("input[name='SpousesName']").val();
                SpousesIDNum = $(this).find("input[name='SpousesIDNum']").val();
                SpousesGJJNum = $(this).find("input[name='SpousesGJJNum']").val();

                if (CustomerName != "" || IDNum != "" || GJJNum != "" || SpousesName != "" || SpousesIDNum != "" || SpousesGJJNum != "") {
                    strRet = strRet + "<tr>";
                    strRet = strRet + "<td style='text-align:center'>" + CustomerName + "</td>";
                    strRet = strRet + "<td style='width:145px;text-align:center'>" + IDNum + "</td>";
                    strRet = strRet + "<td style='width:125px;text-align:center'>" + GJJNum + "</td>";
                    strRet = strRet + "<td style='text-align:center'>" + SpousesName + "</td>";
                    strRet = strRet + "<td style='width:145px;text-align:center'>" + SpousesIDNum + "</td>";
                    strRet = strRet + "<td style='width:125px;text-align:center'>" + SpousesGJJNum + "</td>";
                    strRet = strRet + "</tr>";
                }
            }
        });

        strRet = strRet + "</tbody>";
        strRet = strRet + "</table>";

        return strRet;
    },
    initEvent: function() {
        var objPg = this;
        /*************事件：预审客户信息*************/
        $("#aPreliminaryUser").click(function() {

            if (!confirm("导入预审客户信息将覆盖已填写数据，确定要导入吗？")) {
                return false;
            }

            var HouseId;
            if (objPg.form.ContractArcInfo != undefined) {
                HouseId = objPg.form.ContractArcInfo.HouseId;
            } else if (objPg.form.HouseInfo != undefined) {
                HouseId = objPg.form.HouseInfo.HouseId;
            }

            Chenxin.ajax({
                type: "get",
                dataType: "json",
                url: objPg.actionUrl,
                data: { op: 'getpreliminaryuser', HouseId: HouseId },
                onSuccess: function(data) {
                    var SalerInfo = [];

                    objPg.form.delVenderInfo();
                    objPg.form.delBuyerInfo();
                    //下家数据
                    if (data.PreBuyerInfo != "") {
                        objPg.form.bindBuyerInfo(data.PreBuyerInfo);
                    } else {
                        objPg.form.bindBuyerInfo();
                    }
                    //上家数据
                    if (data.PreSalerInfo != null) {
                        data.PreSalerInfo.CustomerName = data.PreSalerInfo.SaleName;
                        data.PreSalerInfo.IDNum = data.PreSalerInfo.SaleIDCard;
                        SalerInfo.push(data.PreSalerInfo);
                        objPg.form.bindVenderInfo(SalerInfo);
                    } else {
                        objPg.form.bindVenderInfo();
                    }
                }
            });
        });
        /*************事件：预览*************/
        $("#aReview").click(function() {
            objPg.jqmReview.resetContent(objPg.getReviewInfo());
            objPg.jqmReview.show();
        });
        /*************事件：提交*************/
        $("#aSubmit").click(function() {
            if (objPg.form.ContractArcInfo != undefined) {
                objPg.form.op = "upd";
            }
            objPg.form.save();
        });
        /*************事件：返回房源管理*************/
        $("a[name='aReturnHouseList']").live("click",function() {

            window.location.href = $("#ctl00_main_hidHouseUrl").val();
        });
    }
});

/*
**签约报备窗体
*/
Chenxin.UI.ContractArchiveForm = Chenxin.extend(Chenxin.UI.AddFormCommon, {
    actionUrl: "/service/logic/ContractArchive.ashx",
    id: "divContext",
    createComboList: function() {

        var jsonInitVal = this.initComboVal();
        /****************************报备信息*************************/
        //报备部门
        var comboDepartId = new Chenxin.UI.StructCombo({
            param: { op: 'getcontroldeparts' },
            containerId: '#DepartId',
            name: 'DepartId',
            inModelType: 'all',
            txtModelName: 'DepartName',
            required: true,
            tbxWidth: 120,
            colNum: 4,
            pageSize: 20,
            hasSearch: true,
            colWidth: 80,
            initValue: jsonInitVal.DepartId,
            onSelected: function() {
                if (this.getValue() != this.defVal) {

                    comboEmployeeId.loadUser(this.getValue());
                }
            },
            afterSetValue: function(newVal, oldVal) {
                if (newVal != "请选择") {
                    comboEmployeeId.loadUser(newVal);
                }
            }
        });
        //报备人员
        var comboEmployeeId = new Chenxin.UI.RichModelTreeCombo({
            textBoxId: 'txtEmployeeId',
            containerId: '#txtEmployeeId',
            inModelType: 'all',
            txtModelName: 'Employee',
            required: true,
            singleSelect: true,
            //initValue:jsonInitVal.EmployeeId,
            name: 'EmployeeId'
        });
        //贷款情况
        var comboLoanInfo = new Chenxin.UI.Combo({
            containerId: '#LoanInfo',
            name: 'LoanInfo',
            required: true,
            tbxWidth: 120,
            colWidth: 80,
            initValue: jsonInitVal.LoanInfo,
            items: comboCommon.ArchiveLoanInfoType
        });
        //合同归属（城市）
        var comboBargainCityId = new Chenxin.UI.StructCombo({
            param: { op: 'getcity' },
            containerId: '#BargainCityId',
            name: 'BargainCityId',
            tbxWidth: 120,
            inModelType: 'all',
            txtModelName: 'BargainCityName',
            initValue: jsonInitVal.BargainCityId,
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    comboBargainCompanyId.clearItems();
                } else {
                    comboBargainCompanyId.param.fatherid = this.getValue();
                    comboBargainCompanyId.reload();
                }
            },
            afterSetValue: function(newVal, oldVal) {
                if (newVal != "请选择") {
                    comboBargainCompanyId.param.fatherid = newVal;
                    comboBargainCompanyId.reload(jsonInitVal.BargainCompanyId);
                }
            }
        });
        //合同归属（公司）
        var comboBargainCompanyId = new Chenxin.UI.StructCombo({
            param: { op: 'getcompany' },
            containerId: '#BargainCompanyId',
            name: 'BargainCompanyId',
            inModelType: 'all',
            txtModelName: 'BargainCompanyName',
            //initValue:jsonInitVal.BargainCompanyId,
            tbxWidth: 120,
            autoLoad: false,
            required: true
        });
        //签约地点（城市）
        var comboWorkCityId = new Chenxin.UI.StructCombo({
            param: { op: 'getcity' },
            containerId: '#WorkCityId',
            name: 'WorkCityId',
            inModelType: 'all',
            txtModelName: 'WorkCityName',
            initValue: jsonInitVal.WorkCityId,
            tbxWidth: 120,
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    comboBargainCompanyId.clearItems();
                } else {
                    comboWorkCompanyId.param.fatherid = this.getValue();
                    comboWorkCompanyId.reload();
                }
                comboWorkCompanyId.clearItems();
                comboWorkDepartId.clearItems();
                comboWorkPersonId.clearItems();
            },
            afterSetValue: function(newVal, oldVal) {
                if (newVal != "请选择") {
                    comboWorkCompanyId.param.fatherid = newVal;
                    comboWorkCompanyId.reload(jsonInitVal.WorkCompanyId);
                }
            }
        });
        //签约地点（公司）
        var comboWorkCompanyId = new Chenxin.UI.StructCombo({
            param: { op: 'getcompany' },
            containerId: '#WorkCompanyId',
            name: 'WorkCompanyId',
            inModelType: 'all',
            txtModelName: 'WorkCompanyName',
            tbxWidth: 120,
            autoLoad: false,
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    comboWorkDepartId.clearItems();
                } else {
                    if ($("input[name='BargainType']:checked").val() == "面签") {
                        comboWorkDepartId.param.op = "getbargaindeparts";
                    } else {
                        comboWorkDepartId.param.op = "getsigndeparts";
                    }
                    comboWorkDepartId.param.fatherid = this.getValue();
                    comboWorkDepartId.reload();
                }
                comboWorkDepartId.clearItems();
                comboWorkPersonId.clearItems();
            },
            afterSetValue: function(newVal, oldVal) {
                if (newVal != "请选择") {
                    if ($("input[name='BargainType']:checked").val() == "面签") {
                        comboWorkDepartId.param.op = "getbargaindeparts";
                    } else {
                        comboWorkDepartId.param.op = "getsigndeparts";
                    }
                    comboWorkDepartId.param.fatherid = newVal;
                    comboWorkDepartId.reload(jsonInitVal.WorkDepartId);
                }
            }
        });
        //签约人
        var comboWorkPersonId = new Chenxin.UI.StructCombo({
            param: { op: 'getemployee' },
            containerId: '#WorkPersonId',
            inModelType: 'all',
            txtModelName: 'WorkPersonName',
            autoLoad: false,
            required: true,
            tbxWidth: 120,
            colNum: 3,
            pageSize: 15,
            hasSearch: true,
            colWidth: 80
        });
        //签约地点（部门）
        var comboWorkDepartId = new Chenxin.UI.StructCombo({
            param: { op: 'getsigndeparts' },
            containerId: '#WorkDepartId',
            inModelType: 'all',
            txtModelName: 'WorkDepartName',
            initValue: jsonInitVal.WorkDepartId,
            tbxWidth: 120,
            colWidth: 80,
            colNum: 3,
            autoLoad: false,
            required: true,
            hasPage: true,
            hasSearch: true,
            pageSize: 60,
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    comboWorkPersonId.clearItems();
                } else {
                    if ($("input[name='BargainType']:checked").val() == "面签") {
                        comboWorkPersonId.param.op = "getcenteruser";
                    } else {
                        comboWorkPersonId.param.op = "getemployee";
                    }
                    comboWorkPersonId.param.fatherid = this.getValue();
                    comboWorkPersonId.reload();
                }
                comboWorkPersonId.clearItems();
            },
            afterSetValue: function(newVal, oldVal) {
                if (newVal != "请选择") {
                    if ($("input[name='BargainType']:checked").val() == "面签") {
                        comboWorkPersonId.param.op = "getcenteruser";
                    } else {
                        comboWorkPersonId.param.op = "getemployee";
                    }
                    comboWorkPersonId.param.fatherid = newVal;
                    comboWorkPersonId.reload(jsonInitVal.WorkPersonId);
                }
            }
        });


        /****************************房源信息*************************/
        //竣工日期
        var comboCompleteYear = new Chenxin.UI.BuildingYearCombo({
            containerId: '#CompleteYear',
            tbxWidth: 120,
            required: true,
            initValue: jsonInitVal.CompleteYear
        });

        //建筑类型
        var comboBuildingType = new Chenxin.UI.ParameterCombo({
            containerId: '#BuildingType',
            name: 'BuildingType',
            key: 'Building.Type',
            inModelType: 'txt',
            autoLoad: true,
            tbxWidth: 120,
            required: true,
            initValue: jsonInitVal.BuildingType
        });
        //物业用途
        var comboHouseUse = new Chenxin.UI.ParameterCombo({
            containerId: '#HouseUse',
            name: 'HouseUse',
            key: 'House.Use',
            inModelType: 'txt',
            tbxWidth: 120,
            required: true,
            initValue: jsonInitVal.HouseUse
        });

        /****************************交易信息*************************/
        //合同总价单位
        var comboUnit = new Chenxin.UI.Combo({
            containerId: '#Unit',
            name: 'Unit',
            addPleaseSelected: false,
            tbxWidth: 40,
            items: comboCommon.PriceUnit
        });
        return [comboDepartId, comboEmployeeId, comboLoanInfo, comboBargainCityId, comboBargainCompanyId, comboWorkCityId, comboWorkCompanyId, comboWorkDepartId, comboWorkPersonId, comboCompleteYear, comboBuildingType, comboHouseUse, comboUnit];
    },
    initFormValidator: function() {
        var objFrm = this;
        //签约时间
        $("#txtBargainTime").formValidator({
            validatorgroup: this.id,
            onshow: "请输入签约时间！",
            onfocus: "签约时间格式：YYYY-MM-DD HH:mm",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "签约时间不能为空！"
            },
            onerror: "签约时间不能为空！"
        });
        //过户日期
        $("#txtTransferDate").formValidator({
            validatorgroup: this.id,
            onshow: "请输入过户日期！",
            onfocus: "过户日期格式：YYYY-MM-DD",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "过户日期不能为空！"
            },
            onerror: "过户日期不能为空！"
        });
        //签贷款时间
        $("#txtLoanTime").formValidator({
            validatorgroup: this.id,
            onshow: "请输入签贷款时间！",
            onfocus: "签贷款时间格式：YYYY-MM-DD HH:mm",
            oncorrect: " "
        }).functionValidator({
            fun: function(val) {
                if (objFrm.comboList[2].getValue() == "一次性付款") {
                    return true;
                } else {
                    if (val == "") {
                        return false;
                    } else {
                        return true;
                    }
                }
            },
            onerror: "签贷款时间不能为空！"
        });
        //联系电话
        $("#txtMobile").formValidator({
            validatorgroup: this.id,
            onshow: "请输入联系电话！",
            onfocus: "联系电话为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "联系电话不能为空！"
            },
            onerror: "联系电话不能为空！"
        });
        //房源地址
        $("#txtNewHouseAddress").formValidator({
            validatorgroup: this.id,
            onshow: "请输入房源地址！",
            onfocus: "房源地址为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "房源地址不能为空！"
            },
            onerror: "房源地址不能为空！"
        });
        //建筑面积
        $("#txtBuildingArea").formValidator({
            validatorgroup: this.id,
            onshow: "请输入建筑面积！",
            onfocus: "建筑面积为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "建筑面积不能为空！"
            },
            onerror: "建筑面积不能为空！"
        });
        //总楼层
        $("#txtTotal_Floor").formValidator({
            validatorgroup: this.id,
            onshow: "请输入总楼层！",
            onfocus: "总楼层为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "总楼层不能为空！"
            },
            onerror: "总楼层不能为空！"
        });
        //房屋楼层
        $("#txtCur_Floor").formValidator({
            validatorgroup: this.id,
            onshow: "请输入房屋楼层！",
            onfocus: "房屋楼层为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "房屋楼层不能为空！"
            },
            onerror: "房屋楼层不能为空！"
        });
        //合同总价
        $("#txtTotalPrice").formValidator({
            validatorgroup: this.id,
            onshow: "请输入合同总价！",
            onfocus: "格式：整数或最多保留2位小数",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "合同总价不能为空！"
            },
            onerror: "合同总价不能为空！"
        }).regexValidator({
            regexp: "decmal7",
            datatype: "enum",
            onerror: "格式不正确"
        });
        // 补偿款
        $("#txtFitPrice").formValidator({
            validatorgroup: this.id,
            onshow: "请输入补偿款！",
            onfocus: "格式：整数或最多保留2位小数",
            oncorrect: " "
        }).regexValidator({
            regexp: "decmal8",
            datatype: "enum",
            onerror: "格式不正确"
        });
        //维修基金
        $("#txtRepairFund").formValidator({
            validatorgroup: this.id,
            onshow: "请输入维修基金！",
            onfocus: "格式：整数或最多保留2位小数或空",
            oncorrect: " "
        }).regexValidator({
            regexp: "decmal8",
            datatype: "enum",
            onerror: "格式不正确"
        });
        //联系地址（出售方）
        $("#txtVenderAddress").formValidator({
            validatorgroup: this.id,
            onshow: "请输入联系地址！",
            onfocus: "联系地址为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "联系地址不能为空！"
            },
            onerror: "联系地址不能为空！"
        });
        //联系电话（出售方）
        $("#txtVenderTel").formValidator({
            validatorgroup: this.id,
            onshow: "请输入联系电话！",
            onfocus: "联系电话为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "联系电话不能为空！"
            },
            onerror: "联系电话不能为空！"
        });
        //产权证号
        $("#txtPropertyCode").formValidator({
            validatorgroup: this.id,
            onshow: "请输入产权证号！",
            onfocus: "产权证号为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "产权证号不能为空！"
            },
            onerror: "产权证号不能为空！"
        });
        //联系地址（买受方）
        $("#txtBuyerAddress").formValidator({
            validatorgroup: this.id,
            onshow: "请输入联系地址！",
            onfocus: "联系地址为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "联系地址不能为空！"
            },
            onerror: "联系地址不能为空！"
        });
        //联系电话（买受方）
        $("#txtBuyerTel").formValidator({
            validatorgroup: this.id,
            onshow: "请输入联系电话！",
            onfocus: "联系电话为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "联系电话不能为空！"
            },
            onerror: "联系电话不能为空！"
        });
    },
    manualPreCheck: function() {

        var bRet = true;
        //出售(甲)方信息
        $("#tbVerder tr").each(function() {
            if ($(this).find("input[name=IDNum]:eq(0)").is("input")) {
                var objIDNum = $(this).find("input[name=IDNum]:eq(0)");
                var objCustomerName = $(this).find("input[name=CustomerName]:eq(0)");
                if (objIDNum.val() != "" & objCustomerName.val() == "") {
                    alert("请输入身份证号");
                    objCustomerName.focus();
                    bRet = false;
                    return false;
                }
            }
        });
        //买受(乙)方信息
        $("#tbBuyer tr").each(function() {
            if ($(this).find("input[name=IDNum]:eq(0)").is("input")) {
                var objIDNum = $(this).find("input[name=IDNum]:eq(0)");
                var objCustomerName = $(this).find("input[name=CustomerName]:eq(0)");
                if (objIDNum.val() != "" & objCustomerName.val() == "") {
                    alert("请输入身份证号");
                    objCustomerName.focus();
                    bRet = false;
                    return false;
                }
            }
        });
        return bRet;
    },
    initEvent: function() {
        var objFrm = this;
        /*************事件：签约时间得到焦点*************/
        $("#txtBargainTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd HH:mm',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
        /*************事件：贷款时间得到焦点*************/
        $("#txtLoanTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd HH:mm',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
        /*************事件：签约方式变更*************/
        $("input[name=BargainType]").click(function() {
            //签约地点重置
            objFrm.comboList[5].setValue(objFrm.comboList[5].defVal);
            objFrm.comboList[6].clearItems();
            objFrm.comboList[7].clearItems();
            objFrm.comboList[8].clearItems();
        });
        
        

        /*************事件：添加出售方*************/
        $("#aAddVender").click(function() {
            objFrm.bindVenderInfo();
        });
        /*************事件：删除出售方*************/
        $("A[name=aDelVender]").live("click", function() {
            if (confirm("确定要删除吗？")) {
                var objOwerTr = $(this).parents("tr:first");
                $(objOwerTr).remove();
            }
        });

        /*************事件：添加买受方*************/
        $("#aAddBuyer").click(function() {
            objFrm.bindBuyerInfo();
        });
        /*************事件：删除买受方*************/
        $("A[name=aDelBuyer]").live("click", function() {
            if (confirm("确定要删除吗？")) {
                var objOwerTr = $(this).parents("tr:first");
                var objOwerBody = $(this).parents("tbody:first");
                var needChk = false;

                //删除的主贷人买方信息
                if ($(objOwerTr).find("input[name='BOwner']").eq(0).attr("checked") == true) {
                    needChk = true;
                }
                $(objOwerTr).remove();
                if (needChk) {
                    if (objOwerBody.children("tr").length > 1) {
                        objOwerBody.children("tr:eq(0)").find("input[name='BOwner']").attr("checked", true);
                    }
                }
            }
        });
    },
    saveSucc: function(data, msg) {

        var strUrl;
        strUrl = '<a title="返回房源管理" href="' + $("#ctl00_main_hidHouseUrl").val() + '">返回房源管理</a>';
        strUrl = strUrl + '<br/><br/>';
        strUrl = strUrl + '<a title="返回签约报备" href="ShowListArchive.aspx">返回签约报备</a>';
        strUrl = strUrl + '<br/><br/>';
        strUrl = strUrl + '<a title="查看该报备" href=ArchiveDetailInfo.aspx?RecordId=' + data + ' >查看该报备</a>';
        Chenxin.Msg.alert.show(strUrl, '下一步', Chenxin.Msg.icon.next);
    },
    afterGetFormJson: function(json) {
        var JsonList = [];
        var trJson = {};
        this.form.additionalParam = {};

        //出售(甲)方信息
        $("#tbVerder tr").each(function() {
            $(this).find("input").each(function() {
                if (this.value != "") {
                    trJson[this.name] = this.value;
                }
            });
            if (trJson.toString() != "{}") {
                JsonList.push(trJson);
            }
            trJson = {};
        });
        //出售方信息
        if (JsonList.toString() != "") {
            this.form.additionalParam.lsVerder = "[" + JsonList.toString() + "]";
        }

        JsonList = [];
        //买受(乙)方信息
        $("#tbBuyer tr").each(function() {
            $(this).find("input").each(function() {
                //单选框
                if (this.type.toLowerCase() == "radio") {
                    //被选中
                    if ($(this).attr("checked")) {
                        trJson[this.name] = true;
                    } else {
                        trJson[this.name] = false;
                    }
                } else {
                    if (this.value != "") {
                        trJson[this.name] = this.value;
                    }
                }
            });
            if (trJson.toString() != "{}" & trJson.toString() != "{BOwner:\"true\"}" & trJson.toString() != "{BOwner:\"false\"}") {
                JsonList.push(trJson);
            }
            trJson = {};
        });
        //买方信息
        if (JsonList.toString() != "") {
            this.form.additionalParam.lsBuyer = "[" + JsonList.toString() + "]";
        }

        //删除出售方，买方详细信息
        delete json.BOwner;
        delete json.CustomerName;
        delete json.IDNum;
        delete json.GJJNum;
        delete json.SpousesName;
        delete json.SpousesIDNum;
        delete json.SpousesGJJNum;
        //房源地址
        json.HouseAddress = json.NewHouseAddress;
        if (this.form.HouseInfo != undefined) {
            json.BelongUserCityId = this.form.HouseInfo.CityId;
            json.BelongUserCompanyId = this.form.HouseInfo.CompanyId;
            json.BelongUserCompanyName = this.form.HouseInfo.CompanyName;
            json.BelongUserDepartmentId = this.form.HouseInfo.OprDepartId;
            json.BelongUserId = this.form.HouseInfo.OprPersonId;
        }
        delete json.OldHouseAddress;
        delete json.NewHouseAddress;
    },
    initForm: function() {
        //初始房源信息
        if ($("#ctl00_main_hidHouseInfo").val() != "") {
            var houseInfo = eval("(" + $("#ctl00_main_hidHouseInfo").val() + ")");
            //有房源信息
            this.HouseInfo = houseInfo;
        }
        //签约报备信息
        if ($("#ctl00_main_hidContractArc").val() != "") {
            var contractArc = eval("(" + $("#ctl00_main_hidContractArc").val() + ")");
            this.ContractArcInfo = contractArc;
            //签约时间
            this.ContractArcInfo.BargainTime = this.ContractArcInfo.BargainTime.substr(0, 16);
            //签贷款时间
            this.ContractArcInfo.LoanTime = this.ContractArcInfo.LoanTime.substr(0, 16);
            //还贷时间
            if (this.ContractArcInfo.PayLoanDay != "" && this.ContractArcInfo.PayLoanDay != null) {
                this.ContractArcInfo.PayLoanDay = (this.ContractArcInfo.PayLoanDay.split(" "))[0];
            }
            //交房时间
            if (this.ContractArcInfo.GiveHouseTime != "" && this.ContractArcInfo.GiveHouseTime != null) {
                this.ContractArcInfo.GiveHouseTime = (this.ContractArcInfo.GiveHouseTime.split(" "))[0];
            }
            //过户日期
            if (this.ContractArcInfo.TransferDate != "" && this.ContractArcInfo.TransferDate != null) {
                this.ContractArcInfo.TransferDate = (this.ContractArcInfo.TransferDate.split(" "))[0];
            }
            //房源源地址
            this.ContractArcInfo.OldHouseAddress = this.ContractArcInfo.HouseAddress;
            //房源地址
            this.ContractArcInfo.NewHouseAddress = this.ContractArcInfo.HouseAddress;

            //出售方信息
            if ($("#ctl00_main_hidVenderInfo").val() != "") {
                var venderInfo = eval("(" + $("#ctl00_main_hidVenderInfo").val() + ")");
                this.VenderInfo = venderInfo;
            }
            //买方信息
            if ($("#ctl00_main_hidBuyerInfo").val() != "") {
                var buyerInfo = eval("(" + $("#ctl00_main_hidBuyerInfo").val() + ")");
                this.BuyerInfo = buyerInfo;
            }
        }
    },
    initComboVal: function() {
        var jsonInitVal = {};
        if (this.HouseInfo != undefined) {
            jsonInitVal.CompleteYear = this.HouseInfo.CompleteYear;
            jsonInitVal.BuildingType = this.HouseInfo.BuildingType;
            jsonInitVal.HouseUse = this.HouseInfo.HouseUse;
            jsonInitVal.Unit = "RMB";
        } else if (this.ContractArcInfo != undefined) {
            jsonInitVal.DepartId = this.ContractArcInfo.DepartId;
            jsonInitVal.EmployeeId = this.ContractArcInfo.EmployeeId;
            jsonInitVal.LoanInfo = this.ContractArcInfo.LoanInfo;
            jsonInitVal.BargainCityId = this.ContractArcInfo.BargainCityId;
            jsonInitVal.BargainCompanyId = this.ContractArcInfo.BargainCompanyId;
            jsonInitVal.WorkCityId = this.ContractArcInfo.WorkCityId;
            jsonInitVal.WorkCompanyId = this.ContractArcInfo.WorkCompanyId;
            jsonInitVal.WorkDepartId = this.ContractArcInfo.WorkDepartId;
            jsonInitVal.WorkPersonId = this.ContractArcInfo.WorkPersonId;
            jsonInitVal.CompleteYear = this.ContractArcInfo.CompleteYear;
            jsonInitVal.BuildingType = this.ContractArcInfo.BuildingType;
            jsonInitVal.HouseUse = this.ContractArcInfo.HouseUse;
            jsonInitVal.Unit = this.ContractArcInfo.Unit;
        }
        return jsonInitVal;
    },
    loadDefVal: function() {

        //房源信息
        if (this.HouseInfo != undefined) {
            var tbHouse = "tbHouse";
            this.HouseInfo.OldHouseAddress = this.HouseInfo.Address;
            this.HouseInfo.BelongUserName = this.HouseInfo.OprPerson;
            this.HouseInfo.BelongUserDepartmentName = this.HouseInfo.OprDepart;
            //绑定页面房源部分
            Chenxin.Fn.setFormValue(tbHouse, {}, this.HouseInfo);
        }
        //签约报备信息
        if (this.ContractArcInfo != undefined) {
            //绑定签约报备信息
            Chenxin.Fn.setFormValue(this.id, this.comboList, this.ContractArcInfo);
            //绑定出售方信息
            if (this.VenderInfo != undefined) {
                this.bindVenderInfo(this.VenderInfo);
            } else {
                this.bindVenderInfo();
            }
            //绑定买方信息
            if (this.BuyerInfo != undefined) {
                this.bindBuyerInfo(this.BuyerInfo);
            }
        } else {
            this.bindVenderInfo();
            this.bindBuyerInfo();
        }
    },
    delVenderInfo: function() {
        $("#tbVerder tbody").children("tr").each(function() {
            if ($(this).find("input[name='CustomerName']").length > 0) {
                $(this).remove();
            }
        });
    },
    delBuyerInfo: function() {
        $("#tbBuyer tbody").children("tr").each(function() {
            if ($(this).find("input[name='CustomerName']").length > 0) {
                $(this).remove();
            }
        });
    },
    bindVenderInfo: function(lsVenderInfo) {
        var htmlTr = "";
        var CustomerName;
        var IDNum;
        var lastElem = $("#tbVerder tbody").children("tr:last");
        if (lsVenderInfo == undefined) {
            htmlTr = "<tr>";
            htmlTr = htmlTr + "<td>";
            htmlTr = htmlTr + "    <input type=text name='CustomerName' class='inputbox_n fl' style='width:146px' />";
            htmlTr = htmlTr + "</td>";
            htmlTr = htmlTr + "<td>";
            htmlTr = htmlTr + "     <input type=text name='IDNum' class='inputbox_n fl' style='width:260px' />";
            htmlTr = htmlTr + "</td>";
            htmlTr = htmlTr + "<td>";
            htmlTr = htmlTr + "     <a href='javascript:void(0)' name='aDelVender'>删除</a>";
            htmlTr = htmlTr + "</td>";
            htmlTr = htmlTr + "</tr>";
        } else {
            for (var iCnt = lsVenderInfo.length - 1; iCnt >= 0; iCnt--) {
                htmlTr = htmlTr + "<tr>";
                htmlTr = htmlTr + "    <td>";
                htmlTr = htmlTr + "        <input type=text name=\"CustomerName\" value=\"" + (lsVenderInfo[iCnt]).CustomerName + "\" class=\"inputbox_n fl\" style=\"width:146px\" />";
                htmlTr = htmlTr + "    </td>";
                htmlTr = htmlTr + "    <td>";
                htmlTr = htmlTr + "        <input type=text name=\"IDNum\" value=\"" + (lsVenderInfo[iCnt]).IDNum + "\" class=\"inputbox_n fl\" style='width:260px' />";
                htmlTr = htmlTr + "    </td>";
                htmlTr = htmlTr + "    <td>";
                htmlTr = htmlTr + "        <a href=\"javascript:void(0)\" name=\"aDelVender\">删除</a>";
                htmlTr = htmlTr + "    </td>";
                htmlTr = htmlTr + "</tr>";
            }
        }
        lastElem.before(htmlTr);
    },
    bindBuyerInfo: function(lsBuyerInfo) {
        var htmlTr = "";
        var lastElem = $("#tbBuyer tbody").children("tr:last");
        if (lsBuyerInfo == undefined) {
            htmlTr = "<tr>";
            htmlTr = htmlTr + "    <td>";
            if ($("#tbBuyer tbody").children("tr").length < 2) {
                htmlTr = htmlTr + "        <input type=radio name='BOwner' checked />";
            } else {
                htmlTr = htmlTr + "        <input type=radio name='BOwner' />";
            }
            htmlTr = htmlTr + "    </td>";
            htmlTr = htmlTr + "    <td>";
            htmlTr = htmlTr + "        <input type=text name='CustomerName' class='inputbox_n fl' style='width:60px' />";
            htmlTr = htmlTr + "    </td>";
            htmlTr = htmlTr + "    <td>";
            htmlTr = htmlTr + "        <input type=text name='IDNum' class='inputbox_n fl' />";
            htmlTr = htmlTr + "    </td>";
            htmlTr = htmlTr + "    <td>";
            htmlTr = htmlTr + "        <input type=text name='GJJNum' class='inputbox_n fl'  style='width:80px' />";
            htmlTr = htmlTr + "    </td>";
            htmlTr = htmlTr + "    <td>";
            htmlTr = htmlTr + "        <input type=text name='SpousesName' class='inputbox_n fl' style='width:60px' />";
            htmlTr = htmlTr + "    </td>";
            htmlTr = htmlTr + "    <td>";
            htmlTr = htmlTr + "        <input type=text name='SpousesIDNum' class='inputbox_n fl' />";
            htmlTr = htmlTr + "    </td>";
            htmlTr = htmlTr + "    <td>";
            htmlTr = htmlTr + "        <input type=text name='SpousesGJJNum' class='inputbox_n fl'   style='width:80px' />";
            htmlTr = htmlTr + "    </td>";
            htmlTr = htmlTr + "    <td>";
            htmlTr = htmlTr + "        <a href='javascript:void(0)' name='aDelBuyer'>删除</a>";
            htmlTr = htmlTr + "    </td>";
            htmlTr = htmlTr + "</tr>";
        } else {
            for (var iCnt = lsBuyerInfo.length - 1; iCnt >= 0; iCnt--) {
                htmlTr = htmlTr + "<tr>";
                htmlTr = htmlTr + "    <td>";
                if ((lsBuyerInfo[iCnt]).BOwner == true) {
                    htmlTr = htmlTr + "        <input type=radio name='BOwner' checked />";
                } else {
                    htmlTr = htmlTr + "        <input type=radio name='BOwner' />";
                }
                htmlTr = htmlTr + "    </td>";
                htmlTr = htmlTr + "    <td>";
                htmlTr = htmlTr + "        <input type=text name='CustomerName' value='" + (lsBuyerInfo[iCnt]).CustomerName + "' class='inputbox_n fl' style='width:60px' />";
                htmlTr = htmlTr + "    </td>";
                htmlTr = htmlTr + "    <td>";
                htmlTr = htmlTr + "        <input type=text name='IDNum' value='" + (lsBuyerInfo[iCnt]).IDNum + "' class='inputbox_n fl' />";
                htmlTr = htmlTr + "    </td>";
                htmlTr = htmlTr + "    <td>";
                htmlTr = htmlTr + "        <input type=text name='GJJNum' value='" + (lsBuyerInfo[iCnt]).GJJNum + "' class='inputbox_n fl'  style='width:80px' />";
                htmlTr = htmlTr + "    </td>";
                htmlTr = htmlTr + "    <td>";
                htmlTr = htmlTr + "        <input type=text name='SpousesName' value='" + (lsBuyerInfo[iCnt]).SpousesName + "' class='inputbox_n fl' style='width:60px' />";
                htmlTr = htmlTr + "    </td>";
                htmlTr = htmlTr + "    <td>";
                htmlTr = htmlTr + "        <input type=text name='SpousesIDNum' value='" + (lsBuyerInfo[iCnt]).SpousesIDNum + "' class='inputbox_n fl' />";
                htmlTr = htmlTr + "    </td>";
                htmlTr = htmlTr + "    <td>";
                htmlTr = htmlTr + "        <input type=text name='SpousesGJJNum' value='" + (lsBuyerInfo[iCnt]).SpousesGJJNum + "' class='inputbox_n fl'   style='width:80px' />";
                htmlTr = htmlTr + "    </td>";
                htmlTr = htmlTr + "    <td>";
                htmlTr = htmlTr + "        <a href='javascript:void(0)' name='aDelBuyer'>删除</a>";
                htmlTr = htmlTr + "    </td>";
                htmlTr = htmlTr + "</tr>";
            }
        }
        lastElem.before(htmlTr);
    }
});

$(document).ready(function(){
    var objPage = new Chenxin.UI.ContractArchivePage();
});